//
//  GPLongPressMenuController.m
//  Keping
//
//  Created by 23 on 2017/12/9.
//  Copyright © 2017年 柯平. All rights reserved.
//

#import "GPLongPressMenuController.h"
#import "GPContactModel.h"



@interface GPLongPressMenuController ()
@property (weak, nonatomic) IBOutlet UIView *contentView;
@property (weak, nonatomic) IBOutlet UILabel *viewProfileLabel;
@property (weak, nonatomic) IBOutlet UILabel *voiceIntercomLabel;
@property (weak, nonatomic) IBOutlet UILabel *videoIntercomLabel;
@property (weak, nonatomic) IBOutlet UILabel *phoneCallLabel;
@property (weak, nonatomic) IBOutlet UILabel *blockUserLabel;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;

@end

@implementation GPLongPressMenuController

- (instancetype)init
{
    if (self = [super init]) {
        
        self.modalPresentationStyle = UIModalPresentationCustom;
        
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.3];
    
    self.nameLabel.text = self.contact.nickName;
    //拨打电话
    NSString *phone;
    if (StringNotNull(self.contact.prix)) {
        phone = [NSString stringWithFormat:@"%@ %@",self.contact.prix,self.contact.phone];
    } else {
        phone = [NSString stringWithFormat:@"%@",self.contact.phone];
    }
    self.phoneCallLabel.text = [NSString stringWithFormat:@"Phone Call(%@)",phone];
    
    //添加手势
    self.viewProfileLabel.tag = GPLongPressMenuTypeProfile;
    self.viewProfileLabel.userInteractionEnabled = YES;
    [self.viewProfileLabel addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapMenu:)]];
    
    self.voiceIntercomLabel.tag = GPLongPressMenuTypeVoice;
    self.voiceIntercomLabel.userInteractionEnabled = YES;
    [self.voiceIntercomLabel addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapMenu:)]];
    
    self.videoIntercomLabel.tag = GPLongPressMenuTypeVideo;
    self.videoIntercomLabel.userInteractionEnabled = YES;
    [self.videoIntercomLabel addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapMenu:)]];
    
    self.phoneCallLabel.tag = GPLongPressMenuTypePhone;
    self.phoneCallLabel.userInteractionEnabled = YES;
    [self.phoneCallLabel addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapMenu:)]];
    
    self.blockUserLabel.tag = GPLongPressMenuTypeBlock;
    self.blockUserLabel.userInteractionEnabled = YES;
    [self.blockUserLabel addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapMenu:)]];
    
    
    self.view.tag = GPLongPressMenuTypeContent; 
    [self.view addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapMenu:)]];
    
    self.phoneCallLabel.text = [NSString stringWithFormat:@"Phone Call(%@%@)", self.contact.prix, self.contact.phone];
}


- (void)setContact:(GPContactModel *)contact {
    _contact = contact;
}





- (void)viewWillLayoutSubviews
{
    [super viewWillLayoutSubviews];
    
    self.contentView.layer.cornerRadius = 8.f;
    self.contentView.layer.masksToBounds = YES;
}

#pragma mark - 事件监听
- (void)tapMenu:(UITapGestureRecognizer *)tap
{
    GPLongPressMenuType type = (GPLongPressMenuType)tap.view.tag;

    [self dismissViewControllerAnimated:NO completion:nil];
    
    if (type == GPLongPressMenuTypeContent) {
        return;
    }
    
    if ([self.delegate respondsToSelector:@selector(menuType:didItemClicked:)]) {
        [self.delegate menuType:type didItemClicked:self.contact];
    }
    
}


@end
